package com.fks.fks_service.mapper;


import com.fks.fks_service.pojo.Admin;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface AdminMapper {

    @Select("select * from kc_admin_user where adminPhone=#{adminPhone}")
    Admin selectUserByPhone(String phone);

    @Select("select * from kc_admin_user where id=#{id}")
    Admin getById(int userId);

    @Select("select id,adminName,account,avatar,adminType,businessHours1,businessHours2,adminAddress" +
            ",briefIntroduction,administratorsName from kc_admin_user where id=#{id}")
    Admin getById2(int userId);

    @Insert("insert into kc_admin_user (account,avatar,reviewStatus,adminPhone,createTime,password,status" +
            ",isDel,adminId)values(#{account},#{avatar},'0',#{adminPhone},#{createTime},#{password}" +
            ",'-1','0',#{adminId})")
    int addAdmin(Admin admin);

    @Select("select * from kc_admin_user where adminId=#{adminId}")
    List<Admin> getAdminList(String adminId);

    @Select("select * from kc_admin_user where account=#{account}")
    Admin getByAccount(String account);

    @Select("select salt from kc_admin_user where id=#{id}")
    String getSaltById(int id);

    @Update("update into kc_admin_user set account=#{account},adminPhone=#{adminPhone},password=#{password}" +
            ",status=#{status},authority=#{authority},isDel=#{isDel},adminId=#{adminId},updateTime=#{updateTime}" +
            ",updateUserId=#{updateUserId} where id=#{id}")
    int updateAdmin(Admin admin);

    @Select("select * from kc_admin_user where adminPhone=#{adminPhone}")
    Admin getAdminByPhone(String phone);

    @Insert("insert into kc_admin_user (account,reviewStatus,adminPhone,createTime,password,status,isSubAccount,isDel" +
            ",adminId)values(#{phone},'0',#{phone},#{now},#{encode},'0',''0'','0',#{adminId}) ")
    int addAdminByPhone(String phone, String encode, String now, String adminId);

    @Select("select * from kc_admin_user where adminName=#{adminName}")
    Admin getAdmin(String adminName);

    @Update("update kc_admin_user set reviewStatus=#{reviewStatus} where id=#{id}")
    int examineAdmin(Integer id, String reviewStatus);

    @Update("update kc_admin_user set status=#{status} where id=#{id}")
    int updateAdminStatus(int id, String status);

    @Update("update kc_admin_user set isDel=#{isDel} where id=#{id}")
    int deletedRecovery(Integer id, String isDel);

    @Select("select * from kc_admin_user where isDel='0' and status='0'")
    List<Admin> getAllAdminList();

    @Update("update kc_admin_user set reviewStatus=#{reviewStatus} where id=#{adminId}")
    int updateAdminReviewStatus(int adminId, String reviewStatus);

    @Update("update kc_admin_user set administratorsName=#{administratorsName},administratorsPhone=#{administratorsPhone}" +
            ",businessHours1=#{businessHours1},businessHours2=#{businessHours2},adminAddress=#{adminAddress}" +
            ",briefIntroduction=#{briefIntroduction},adminName=#{adminName} where id=#{adminId}")
    int updateAdminInformation(int adminId, String adminName, String administratorsName, String administratorsPhone, String businessHours1, String businessHours2, String adminAddress, String briefIntroduction);

    @Update("update kc_admin_user set balance=#{balance} where id=#{id}")
    int updateBalance(Admin admin);

    @Update("update kc_admin_user set pendingReviewBalance=#{pendingReviewBalance} where id=#{id}")
    int updatePendingReviewBalance(Admin admin);

    @Update("update kc_admin_user set withdrawableBalance=#{withdrawableBalance} where id=#{id}")
    int updateWithdrawableBalance(Admin admin);

    @Select("select account,avatar,reviewStatus,adminPhone,status,administratorsPhone,businessHours1,businessHours2" +
            ",adminAddress,briefIntroduction,enteringIndustry from kc_admin_user where id=#{adminId}")
    Admin getAdminInformationById(Integer adminId);
}
